package com.lianwei.hospital.Service.Impl;

import com.lianwei.hospital.Service.ErInfoService;
import com.lianwei.hospital.mapper.ErInfoMapper;
import com.lianwei.hospital.module.entity.BookingInfo;
import com.lianwei.hospital.module.entity.ErInfo;
import com.lianwei.hospital.module.vo.ErVO;
import com.lianwei.hospital.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("ErInfoService")
public class ErInfoImpl implements ErInfoService {
    @Autowired
    ErInfoMapper erInfoMapper;

    @Override
    public ErInfo selectByPrimaryKey(String id) throws Exception {
        return erInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean insert(ErInfo erInfo) throws Exception {
        return erInfoMapper.insert(erInfo)>0;
    }

    @Override
    public List<ErInfo> selectAll() throws Exception {
        return erInfoMapper.selectAll();
    }

    @Override
    public boolean deleteByPrimaryKey(String id) throws Exception {
        return erInfoMapper.deleteByPrimaryKey(id)>0;
    }

    @Override
    public boolean updateByPrimaryKey(ErInfo erInfo) throws Exception {
        return erInfoMapper.updateByPrimaryKey(erInfo)>0;
    }

    @Override
    public PageUtil<ErInfo> findPage(ErVO query) throws Exception {
        /*
         * 1.获取总记录数
         * 2.如果总记录数 > 0 查询数据
         *  将数据封装到PageUtil
         * 否则，返回null
         */
        int count=erInfoMapper.countBySelectActive(query);
        if (count>0){
            List<ErInfo> data=erInfoMapper.selectListBySelectActive(query);
            return new PageUtil<>(query.getCurrentPage(),query.getPageSize(),count,data);
        }
        return null;
    }
}
